local sk__guixin = fk.CreateSkill {

  name = "sk__guixin",

  tags = {  },

}



sk__guixin:addEffect(fk.Damaged, {
  name = "sk__guixin",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for _ = 1, data.damage do
      if self.cancel_cost or not player:hasSkill(sk__guixin.name) or
      table.every(player.room:getOtherPlayers(player), function (p) return p:isAllNude() end) then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askForSkillInvoke(player, sk__guixin.name, data) then
      room:doIndicate(player.id, table.map(room.alive_players, Util.IdMapper))
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = 0
    while table.find(room:getOtherPlayers(player), function (p) return not p:isAllNude() end) and n < 4 do
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if player.dead then return end
        if not p.dead and not p:isAllNude() then
          n = n + 1
          room:moveCardTo(table.random(p:getCardIds("hej")), Card.PlayerHand, player, fk.ReasonPrey, sk__guixin.name, nil, false, player)
        end
      end
    end
    if not player.dead then
      player:turnOver()
    end
  end,
})

return sk__guixin